home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / bbs / fcfgw40s.zip / FILECFGD.CPP < prev    next >
C/C++ Source or Header  |  1996-04-20  |  6KB  |  238 lines

  1. // FileCFGDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdio.h"
  5. #include "stdlib.h"
  6. #include "string.h"
  7. #include "stdafx.h"
  8. #include "FileCFG.h"
  9. #include "FileCFGDlg.h"
  10. #include "FileArea.h"
  11. #include "tipdlg.h"
  12. #include <ctype.h>
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CFileCFGDlg dialog
  22.  
  23. CFileCFGDlg::CFileCFGDlg(CWnd* pParent /*=NULL*/)
  24.     : CDialog(CFileCFGDlg::IDD, pParent)
  25. {
  26.     //{{AFX_DATA_INIT(CFileCFGDlg)
  27.     //}}AFX_DATA_INIT
  28.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  29.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  30. }
  31.  
  32. void CFileCFGDlg::DoDataExchange(CDataExchange* pDX)
  33. {
  34.     CDialog::DoDataExchange(pDX);
  35.     //{{AFX_DATA_MAP(CFileCFGDlg)
  36.     //}}AFX_DATA_MAP
  37. }
  38.  
  39. BEGIN_MESSAGE_MAP(CFileCFGDlg, CDialog)
  40.     //{{AFX_MSG_MAP(CFileCFGDlg)
  41.     ON_WM_SYSCOMMAND()
  42.     ON_WM_DESTROY()
  43.     ON_WM_PAINT()
  44.     ON_WM_QUERYDRAGICON()
  45.     ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
  46.     ON_BN_CLICKED(IDC_BUTTON_REINDEX, OnButtonReindex)
  47.     ON_BN_CLICKED(IDC_BUTTON_FILE_AREAS, OnButtonFileAreas)
  48.     ON_WM_CREATE()
  49.     //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CFileCFGDlg message handlers
  54.  
  55. BOOL CFileCFGDlg::OnInitDialog()
  56. {
  57.     CDialog::OnInitDialog();
  58.  
  59.     // Add "About..." menu item to system menu.
  60.  
  61.     // IDM_ABOUTBOX must be in the system command range.
  62.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  63.     ASSERT(IDM_ABOUTBOX < 0xF000);
  64.  
  65.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  66.     CString strAboutMenu;
  67.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  68.     if (!strAboutMenu.IsEmpty())
  69.     {
  70.         pSysMenu->AppendMenu(MF_SEPARATOR);
  71.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  72.     }
  73.  
  74.     // Set the icon for this dialog.  The framework does this automatically
  75.     //  when the application's main window is not a dialog
  76.     SetIcon(m_hIcon, TRUE);            // Set big icon
  77.     SetIcon(m_hIcon, FALSE);        // Set small icon
  78.  
  79.     // TODO: Add extra initialization here
  80.     if( !getenv("PROBOARD") ){
  81.         MessageBox("PROBOARD environment not set!", "FileCFG/32",MB_ICONERROR|MB_OK);
  82.         OnOK();
  83.     }
  84.  
  85.     strcpy(m_SysPath, getenv("PROBOARD"));
  86.  
  87.     return TRUE;  // return TRUE  unless you set the focus to a control
  88. }
  89.  
  90. void CFileCFGDlg::OnSysCommand(UINT nID, LPARAM lParam)
  91. {
  92.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  93.     {
  94.         CAboutDlg dlgAbout;
  95.         dlgAbout.DoModal();
  96.     }
  97.     else
  98.     {
  99.         CDialog::OnSysCommand(nID, lParam);
  100.     }
  101. }
  102.  
  103. void CFileCFGDlg::OnDestroy()
  104. {
  105.     WinHelp(0L, HELP_QUIT);
  106.     CDialog::OnDestroy();
  107. }
  108.  
  109. // If you add a minimize button to your dialog, you will need the code below
  110. //  to draw the icon.  For MFC applications using the document/view model,
  111. //  this is automatically done for you by the framework.
  112.  
  113. void CFileCFGDlg::OnPaint()
  114. {
  115.     if (IsIconic())
  116.     {
  117.         CPaintDC dc(this); // device context for painting
  118.  
  119.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  120.  
  121.         // Center icon in client rectangle
  122.         int cxIcon = GetSystemMetrics(SM_CXICON);
  123.         int cyIcon = GetSystemMetrics(SM_CYICON);
  124.         CRect rect;
  125.         GetClientRect(&rect);
  126.         int x = (rect.Width() - cxIcon + 1) / 2;
  127.         int y = (rect.Height() - cyIcon + 1) / 2;
  128.  
  129.         // Draw the icon
  130.         dc.DrawIcon(x, y, m_hIcon);
  131.     }
  132.     else
  133.     {
  134.         CDialog::OnPaint();
  135.     }
  136. }
  137.  
  138. // The system calls this to obtain the cursor to display while the user drags
  139. //  the minimized window.
  140. HCURSOR CFileCFGDlg::OnQueryDragIcon()
  141. {
  142.     return (HCURSOR) m_hIcon;
  143. }
  144.  
  145. void CFileCFGDlg::OnButtonExit()
  146. {
  147.     OnOK();
  148. }
  149.  
  150. // This is the reindexing function:
  151. //
  152. // it uses the ProBoard path to locate the file
  153. // area configuration, reads it area by area and
  154. // rebuilds the FILES.BBS index.
  155. void CFileCFGDlg::OnButtonReindex()
  156. {
  157.     CProgressDlg *dlg;
  158.     CFile         idx, src, bbs;
  159.     TFileArea     area;
  160.     char          idxPath[_MAX_PATH],
  161.                   srcPath[_MAX_PATH];
  162.     int           n;
  163.     ushort        nArea = 0;
  164.  
  165.     sprintf(idxPath, "%s\\FILESIDX.PB", m_SysPath);
  166.     sprintf(srcPath, "%s\\FILECFG.PRO", m_SysPath);
  167.  
  168.     if(!src.Open(srcPath, CFile::modeRead|CFile::shareDenyWrite))
  169.         return;
  170.     if(!idx.Open(idxPath, CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite)){
  171.         src.Close();
  172.         return;
  173.     }
  174.     n = int(src.GetLength() / sizeof(TFileArea));
  175.  
  176.     dlg = new CProgressDlg;
  177.     dlg->Create(this);
  178.     dlg->SetRange(0, n);
  179.     dlg->SetStep(1);
  180.  
  181.     n = src.Read(&area, UINT(sizeof(area)));
  182.     while( n == sizeof(area) ){
  183.         nArea++;
  184.         if( '\0' != area.name[0] ){
  185.             CString name = area.name;
  186.             name.AnsiToOem();
  187.             dlg->SetStatus(name);
  188.             MakeIndex(nArea, area, idx);
  189.         }
  190.         dlg->StepIt();
  191.         n = src.Read(&area, UINT(sizeof(area)));
  192.     }
  193.     delete dlg;
  194. }
  195.  
  196. void CFileCFGDlg::MakeIndex(ushort nArea, TFileArea &area, CFile &idx)
  197. {
  198.     CStdioFile bbs;
  199.     BOOL       more;
  200.     CString    line;
  201.  
  202.     if(!bbs.Open(area.listpath, CFile::typeText|CFile::modeRead|CFile::shareDenyWrite))
  203.         return;
  204.  
  205.     more = bbs.ReadString(line);
  206.     while( more ){
  207.         CString name = line.SpanExcluding(" \t");
  208.         if(!name.IsEmpty() && !strchr(";!+", name[0]) && isprint(name[0]) ){
  209.             // we have a file name, write it
  210.             TFileIndex index;
  211.             name.MakeUpper();
  212.             strcpy(index.name, LPCTSTR(name));
  213.             index.area = nArea;
  214.             idx.Write(&index, sizeof(index));
  215.         }
  216.         more = bbs.ReadString(line);
  217.     }
  218.     bbs.Close();
  219. }
  220.  
  221. void CFileCFGDlg::OnButtonFileAreas()
  222. {
  223.     CFileArea *dlg = new CFileArea;
  224.  
  225.     if( dlg ){
  226.         dlg->DoModal();
  227.         delete dlg;
  228.     }
  229. }
  230.  
  231.  
  232. int CFileCFGDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  233. {
  234.     theApp.ShowSplashScreen();
  235.     theApp.ShowTipAtStartup();
  236.     return CDialog::OnCreate(lpCreateStruct);
  237. }
  238.